<template>
	<view class="page">
		<view class="recharge-cont">
			<view class="recharge-cont-title">充值金额</view>
			<view class="recharge-cont-list flex">
				<view class="recharge-cont-list-item" @tap="moneyClick(index, item.money)" :class="{selected:moneyIndex == index}" v-for="(item,index) in moneyList" :key="index">{{item.text}}</view>
			</view>
		</view>
		<view class="recharge-cont">
			<view class="recharge-cont-title">支付方式</view>
			<view class="pay-list">
				<view class="pay-list-item flex" @tap="togglePay(way.type)" v-for="(way,wIndex) in payList" :key="wIndex" v-if="way.type !='jewel_granary'">
					<view class="pay-list-item-pay flex">
						<image class="pay-list-item-pay-icon" :src="way.icon_text"></image>
						<view class="pay-list-item-pay-text">{{way.name}}</view>
					</view>
					<image class="pay-list-item-pay-arrow" :src="payType == way.type ? '/static/icons/pay-select-act.png' : '/static/icons/pay-select.png'"></image>
				</view>
			</view>
		</view>
		<view class="recharge-btn" :class="{gay:!payType}" @tap="rechargeBtn">充值</view>
	</view>
</template>
<script>
	import jewel from '@/common/common_zb.js';
	export default {
		data() {
			return {
				moneyList:[],
				moneyTxt:[],
				moneyIndex:0,
				payType: '',
				payList: []
			};
		},
        methods: {
			getPayList(){
				let that = this
				jewel.get('Payment/payList',{},true,function(res){
					that.payList = res.data.data
				})
			},
			getMoneyList(){
				let that = this
				jewel.get('Maker/recharge_index',{},true,function(res){
					uni.hideLoading()
					that.moneyList = res.data.data;
				})
			},
			moneyClick(index, money){
				this.moneyIndex = index;
			},
			togglePay(type){
				this.payType = type
			},
			rechargeBtn(){
				let that = this
				let data = {
					money:that.moneyList[that.moneyIndex].money,
					paytype:that.payType
				}
				if(!data.paytype) return false
				uni.showLoading()
				jewel.get('Maker/recharge_pay',data,true,function(res){
					uni.hideLoading({title:'充值中'})
					switch (data.paytype) {
					    case 'wxpay':
						case 'alipay':
							let pay_data = res.data.data;
					        uni.requestPayment({
					            provider: that.payType,
					            orderInfo: pay_data,
					        	// #ifdef MP-WEIXIN
					        	nonceStr: pay_data.nonceStr,
					        	timeStamp: pay_data.timeStamp,
					        	package: pay_data.package,
					        	signType: pay_data.signType,
					        	paySign: pay_data.paySign,
					        	// #endif
					            success: (res) => {
					                jewel.showToast('充值成功', 1500);
									setTimeout(()=>{
										uni.navigateTo({
											url:'/pages/jewel/agent_jewel/maker_coupon_record?pageType=recharge'
										})
									},1500)
									that.payType = ''
									that.moneyIndex = 0
					            },
					            fail: (res) => {
					                jewel.showToast('充值失败');
					            }
					        })
					    break;
					}
					
				})
			}
        },
        onLoad() {
			uni.showLoading({
				title:'加载中'
			})
			this.getPayList()
			this.getMoneyList()
        },
		onNavigationBarButtonTap(e) {
			if(e.index == 0){
				uni.navigateTo({
					url:'/pages/jewel/agent_jewel/maker_coupon_record?pageType=recharge'
				})
			}
		}
	}
</script>
<style lang="scss">
	.flex{
		display: flex;
	}
	.page{
		.recharge-cont{
			background-color: #FFFFFF;
			width: 100%;
			border-radius: 5px;
			margin-top: 15rpx;
			padding-left: 26rpx;
			box-sizing: border-box;
			padding-bottom: 20rpx;
			&-title{
				font-size: 32rpx;
				line-height: 90rpx;
				position: relative;
				padding-left: 20rpx;
				&::after{
					content: '';
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
					background-color: #ea4040;
					width: 4rpx;
					height: 26rpx;
					border-radius: 5rpx;
				}
			}
			&-list{
				flex-wrap: wrap;
				&-item{
					width: 220rpx;
					height: 118rpx;
					border: 1px solid #656565;
					border-radius: 8px;
					margin-right: 15rpx;
					margin-bottom: 20rpx;
					text-align: center;
					font-size: 34rpx;
					color: #bfbfbf;
					line-height: 118rpx;
					align-items: center;
					justify-content: center;
				}
				.selected{
					border-color: #d71511;
					color: #FF0000;
				}
			}
			.pay-list{
				&-item{
					align-items: center;
					justify-content: space-between;
					&-pay{
						align-items: center;
						font-size: 32rpx;
						line-height: 108rpx;
						&-icon{
							width: 64rpx;
							height: 64rpx;
							display: block;
							margin-right: 30rpx;
						}
						&-arrow{
							width: 42rpx;
							height: 42rpx;
							margin-right: 30rpx;
						}
					}
				}
				
			}
		}
		.recharge-btn{
			width: 716rpx;
			line-height: 108rpx;
			background-color: #d71511;
			color: #FFFFFF;
			text-align: center;
			font-size: 36rpx;
			border-radius: 50px;
			position: fixed;
			bottom: 20rpx;
			left: 50%;
			margin-left: -358rpx;
			&.gay{
				background-color: #CCCCCC;
			}
		}
	}
	
</style>
